import matplotlib.pyplot as plt
import time

import datetime as dt
import easyquotation


import json,requests,datetime;    


import pandas as pd  #
import random

import numpy as np


def recv_markets():
    quotation = easyquotation.use('sina')
    class Market:
        def _init__(self):
            self.lastPx = 0
            self.ask1 = 0
            self.bid1 = 0
            self.ask_vol1 = 0
            self.bid_vol1 = 0
            self.trade_vol = 0
            self.open_price = 0
            self.time = dt.datetime.now()

    while(True):
        market = str(quotation.real('sh600000')) # 新浪 ['sina'] 腾讯 ['tencent', 'qq'] 
        print(market)
        market = market.replace("'", '"')
        market_json = json.loads(market)
        
        msg = Market()
        msg.lastPx     =  market_json["600000"]["now"]
        msg.ask1       =  market_json["600000"]["ask1"]
        msg.bid1       =  market_json["600000"]["bid1"]
        msg.ask_vol1   =  market_json["600000"]["ask1_volume"]
        msg.bid_vol1   =  market_json["600000"]["bid1_volume"]
        msg.trade_vol  =  market_json["600000"]["turnover"]
        msg.open_price =  market_json["600000"]["open"]


        print(msg.lastPx      )
        print(msg.ask1        )
        print(msg.bid1        )
        print(msg.ask_vol1    )
        print(msg.bid_vol1    )
        print(msg.trade_vol   )
        print(msg.open_price  )
        time.sleep(3)
        



recv_markets()

